package at.dahu4wa.fxclient.modules.imageview;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;

public class SliderObject extends HBox {
	Slider sl;
	Label lb;
	Label val;
	
	public String getLabel(){
		
		return lb.getText();
		
	}
	
	
	
	
	public SliderObject(String title , final IFValChanged callback){
		
		this.setSpacing(10);
		this.setStyle("-fx-border: 2px solid; -fx-border-color: red;");
		lb = new Label(title);
		val = new Label("");
		
		Slider sl = new Slider();
		sl.setMin(0);
		sl.setMax(100);

		this.getChildren().add(lb);
		this.getChildren().add(sl);
		this.getChildren().add(val);
		val.setText(String.format("%.2f", sl.getValue()));
		
		
		sl.valueProperty().addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> ov,
                Number old_val, Number new_val) {
                    val.setText(String.format("%.2f", new_val));
                    callback.setValue(new_val.doubleValue());
            }
		
		});

	}
	
}
